<template>
  <section class="page">
    <data-form :model="model" @onSearch="refreshData" :page="pageService">
      <template slot="default-input">
        <el-form-item label="产品名称" prop="productName">
          <el-input v-model="model.productName"></el-input>
        </el-form-item>
        <el-form-item label="产品状态" prop="productStatus">
          <el-select size="small" v-model="model.productStatus">
            <el-option v-for="{code,name} in this.$dict.getDict(DictType.ProductStatus)" :key="code" :label="name" :value="code"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="删除" prop="isDelete">
          <el-select size="small" v-model="model.isDelete">
            <el-option label="是" value="true"></el-option>
            <el-option label="否" value="false"></el-option>
          </el-select>
        </el-form-item>
      </template>
    </data-form>

    <data-box :page="pageService" @onPageChange="refreshData" :data="dataList">
      <template slot="columns">
        <el-table-column prop="productName" label="产品名称" :min-width="$helper.getColumnWidth(4)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="productContent" label="产品内容" :min-width="$helper.getColumnWidth(6)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="productPrice" label="产品价格" :min-width="$helper.getColumnWidth(3)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="productStatus" label="产品状态" :min-width="$helper.getColumnWidth(3)" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{$dict.dictConvert('ProductStatus', scope.row.productStatus)}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="isDelete" label="删除" :min-width="$helper.getColumnWidth(2)" show-overflow-tooltip>
          <template slot-scope="scope">
            <span v-if="scope.row.isDelete === true">是</span>
            <span v-else>否</span>
          </template>
        </el-table-column>
        <el-table-column prop="remark" label="产品说明" :min-width="$helper.getColumnWidth(6)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="createTime" label="创建时间" :min-width="$helper.getColumnWidth(3)" show-overflow-tooltip>
        </el-table-column>
      </template>
    </data-box>
  </section>
</template>


<script lang="ts">
import Vue from "vue";
import Component from "vue-class-component";
import { Layout, Dependencies } from "~/core/decorator";
import { PageService } from "~/util/page.service";
import DataBox from "~/components/common/data-box.vue";
import DataForm from "~/components/common/data-form.vue";
import { ProductService } from "~/service/service-product/product.service";
import { DictType } from '~/config/enum/dict/dict-type.enum';

@Layout("workspace")
@Component({
  components: {
    DataBox,
    DataForm
  }
})
export default class ProductSearch extends Vue {
  @Dependencies(PageService)
  private pageService: PageService
  @Dependencies(ProductService)
  private productService: ProductService

  private DictType: any = DictType

  private model: any = {
    productName: '',
    productStatus: null,
    isDelete: null,
  }

  private dataList: any[] = []

  private activated() {
    this.refreshData()
  }

  private refreshData() {
    this.productService.findListByPage(this.model, this.pageService).subscribe(
      data => this.dataList = data || [],
      error => this.$message.error(error.msg)
    )
  }
}
</script>
<style lang="less">
</style>


